<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class FileWrite {
    

    /**
     * 写入文件
     * @param <String> $sql
     */
    static function writeTableAccess($sql) {
        if(!empty($sql)) {
            $fp     = self::write(ROOT.'/table/access.sql', $sql);
        }
    }

    /**
     * 写入文件
     * @param <type> $uid
     * @param <type> $uhash
     * @param <type> $name
     */
    static function writeTableIe($uid=0,$uhash, $name){
        $sql    = "INSERT u22_url_ie (uid,uhash, name) values ($uid,'$uhash', '$name') ON DUPLICATE KEY UPDATE click=click+1;" . getBr();
        $fp     = self::write(ROOT.'/table/ie.sql', $sql);
    }
    
    /**
     * 写入文件
     * @param <type> $uid
     * @param <type> $uhash
     * @param <type> $name
     */
    static function writeTableOs($uid=0,$uhash, $name){
        $sql    = "INSERT u22_url_os (uid,uhash, name) values ($uid,'$uhash', '$name') ON DUPLICATE KEY UPDATE click=click+1;". getBr();
        $fp     = self::write(ROOT.'/table/os.sql', $sql);
    }
    
    /**
     * 写入文件
     * @param <type> $uid
     * @param <type> $uhash
     * @param <type> $name
     */
    static function writeTableReferer($uid=0,$uhash, $name){
        $sql    = "INSERT u22_url_referer (uid,uhash, name) values ($uid,'$uhash', '$name') ON DUPLICATE KEY UPDATE click=click+1;". getBr();
        $fp     = self::write(ROOT.'/table/referer.sql', $sql);
    }
    
    /**
     * 写入文件
     * @param <type> $uid
     * @param <type> $uhash
     * @param <type> $name
     */
    static function writeTableSpider($uid=0,$uhash, $name){
        if(!empty($name)){
            $sql    = "INSERT u22_url_spider (uid,uhash, name) values ($uid,'$uhash', '$name') ON DUPLICATE KEY UPDATE click=click+1;". getBr();
            $fp     = self::write(ROOT.'/table/spider.sql', $sql);
        }
    }

    static function writeTableProvince($uid=0,$uhash, $name){
        if(!empty($name)){
            $sql    = "INSERT u22_url_province (uid,uhash, name) values ($uid,'$uhash', '$name') ON DUPLICATE KEY UPDATE click=click+1;". getBr();
            $fp     = self::write(ROOT.'/table/province.sql', $sql);
        }
    }

    static public function write($file, $data) {
        $br = getBr();
        $fp = fopen($file, 'a+');
        flock($fp, LOCK_EX);
        fwrite($fp, $data);
        flock($fp, LOCK_UN);
        fclose($fp);
    }
}
?>
